package com.xinyue.fishinghunter.center.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xinyue.center.messages.response.VoPlayerBasic;
import com.xinyue.center.service.AbstractPlayerService;
import com.xinyue.fishinghunter.dao.FishingHunterPlayerDao;
import com.xinyue.fishinghunter.dao.entity.FishingHunterPlayer;
import com.xinyue.framework.dao.entity.PlayerBasic;

@Service
public class PlayerService extends AbstractPlayerService {

	@Autowired
	private FishingHunterPlayerDao playerDao;

	@Override
	public VoPlayerBasic getVoPlayer(PlayerBasic playerBasic) {
		VoPlayerBasic voPlayerBasic = new VoPlayerBasic();
		FishingHunterPlayer player = (FishingHunterPlayer) playerBasic;
		voPlayerBasic.setPlayerId(player.getPlayerId());
		voPlayerBasic.setNickName(player.getNickName());
		voPlayerBasic.setLevel(player.getLevel());
		voPlayerBasic.setLastLoginTime(player.getLastLoginTime());
		return voPlayerBasic;
	}

	@Override
	protected PlayerBasic createRealPlayer(PlayerBasic playerBasic) {
		FishingHunterPlayer player = new FishingHunterPlayer();
		player.setUserId(playerBasic.getUserId());
		player.setNewCreate(true);
		player.setPlayerId(playerBasic.getPlayerId());
		player.setNickName(playerBasic.getNickName());
		player.setLastLoginTime(System.currentTimeMillis());
		player.setCreateTime(player.getLastLoginTime());
		return player;
	}

	@Override
	public void updatePlayer(PlayerBasic playerBasic) {
		FishingHunterPlayer player = (FishingHunterPlayer) playerBasic;
		playerDao.saveOrUpdate(player, player.getPlayerId());
	}

}
